package com.action;

import java.util.ArrayList;
import java.util.List;

import metier.Imetier;
import model.Site;
import model.builtwith.AnalyseBuiltwith;
import model.builtwith.Categorie;
import model.builtwith.Thechnologie;
import model.header.AnalyseHeader;
import model.header.Header;
import model.performance.AnalysePerformance;

import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class Performance extends ActionSupport {
	@Autowired
	private Imetier metier;

	private Long idSite;
	private Site site;
	private double tempsReponse;
	private double taille;
	private List<List<Thechnologie>> tech = new ArrayList<List<Thechnologie>>();
	private List<Categorie> cat;
	private List<AnalyseHeader>anal=new ArrayList<AnalyseHeader>();
	private List<Header> header;

	public String execute() {
		return Action.SUCCESS;
	}

	public List<AnalyseHeader> getAnal() {
		return anal;
	}

	public void setAnal(List<AnalyseHeader> anal) {
		this.anal = anal;
	}

	
	
	public List<Header> getHeader() {
		return header;
	}

	public void setHeader(List<Header> header) {
		this.header = header;
	}

	public Imetier getMetier() {
		return metier;
	}

	public void setMetier(Imetier metier) {
		this.metier = metier;
	}

	public Long getIdSite() {
		return idSite;
	}

	public void setIdSite(Long idSite) {
		this.idSite = idSite;
	}

	public double getTempsReponse() {
		return tempsReponse;
	}

	public void setTempsReponse(double tempsReponse) {
		this.tempsReponse = tempsReponse;
	}

	public double getTaille() {
		return taille;
	}

	public void setTaille(double taille) {
		this.taille = taille;
	}

	public List<List<Thechnologie>> getTech() {
		return tech;
	}

	public void setTech(List<List<Thechnologie>> tech) {
		this.tech = tech;
	}

	public List<Categorie> getCat() {
		return cat;
	}

	public void setCat(List<Categorie> cat) {
		this.cat = cat;
	}

	public String performance() {
		this.site = this.metier.findSitebyId(this.idSite);
		metier.ajouteranalysePerformence(site.getId_site());
		metier.ajouteranalysebuilth(site.getId_site());
		metier.ajouteranalyseheader(site.getId_site());
		this.site = this.metier.findSitebyId(this.idSite);
		List<AnalyseBuiltwith> analyseBuiltWith = this.site.getBuilt();
		this.cat = analyseBuiltWith.get(analyseBuiltWith.size() - 1).getCat();
		System.out.println(this.cat.size());
		System.out.println(this.cat.get(this.cat.size() - 1).getTech().size());
		int i = 0;
		this.tech = new ArrayList<List<Thechnologie>>();
		for (Categorie categori : this.cat) {
			this.tech.add(categori.getTech());
		}
		List<AnalysePerformance> analysePerfor = this.site.getPerform();
		this.taille = analysePerfor.get(analysePerfor.size() - 1).getTaille();
		this.tempsReponse = analysePerfor.get(analysePerfor.size() - 1)
				.getTempsReponse();
		
		anal=site.getAnalHead();
	       header=anal.get(anal.size()-1).getHeader();
		
		return "success";
	}

}
